#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "hmi_cmd.h"


#define  END_CHAR       "\xff\xff\xff"  /*  指令结尾  */
#define  DEFAULT_CMD_RX_TIMEOUT   500   /*  有返回的指令500ms内没返回则超时  */


void hmi_cmd_send(char *cmd)
{
    if (!cmd) return;
    usart2_send_data((uint8_t *)cmd, strlen(cmd));
    usart2_send_data((uint8_t *)END_CHAR, strlen(END_CHAR));
}

void api_page(int id)
{
    char buf[128];
    snprintf(buf, 128, "page %d", id);
    hmi_cmd_send(buf);
}

void api_cls(int color) {
    char buf[128];
    snprintf(buf, 128, "cls %d", color);
    hmi_cmd_send(buf);
}

void api_line(int x, int y, int x2, int y2, int color) {
    char buf[128];
    snprintf(buf, 128, "line %d,%d,%d,%d,%d", x, y, x2, y2, color);
    hmi_cmd_send(buf);
}

void api_rect(int x, int y, int x2, int y2, int color) {
    char buf[128];
    snprintf(buf, 128, "draw %d,%d,%d,%d,%d", x, y, x2, y2, color);
    hmi_cmd_send(buf);
}

void api_cirs(int x, int y, int r, int color) {
    char buf[128];
    snprintf(buf, 128, "cirs %d,%d,%d,%d", x, y, r, color);
    hmi_cmd_send(buf);
}

void api_bkcmd(int val) {
    char buf[128];
    snprintf(buf, 128, "bkcmd=%d", val);
    hmi_cmd_send(buf);
}

void api_fill(int x, int y, int w, int h, int color) {
    char buf[128];
    snprintf(buf, 128, "fill %d,%d,%d,%d,%d", x, y, w, h, color);
    hmi_cmd_send(buf);
}


/*******************************END OF FILE************************************/



